<template>
  <AdminLayout>
    <div class="products-management" style="min-height: calc(100vh - 60px);">
      <div class="page-header">
        <h2>产品管理</h2>
      </div>
      
      <div class="search-filter">
        <div class="search-box">
          <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M11 19C15.42 19 19 15.42 19 11C19 6.58 15.42 3 11 3C6.58 3 3 6.58 3 11C3 15.42 6.58 19 11 19ZM21 21L16.65 16.65" stroke="#999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
          <input type="text" placeholder="搜索产品..." v-model="searchQuery"/>
        </div>
        <div class="filter-select">
          <select v-model="categoryFilter">
            <option value="all">全部分类</option>
            <option v-for="category in categories" :key="category" :value="category">
              {{ category }}
            </option>
          </select>
        </div>
        <div class="search-actions">
          <button class="search-button" @click="performSearch">
            搜索
          </button>
          <button class="reset-button" @click="resetFilters">
          重置
        </button>
        <button class="add-button" @click="showAddProductModal = true">
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M12 5V19M5 12H19" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
          </svg>
          添加产品
        </button>
        <button class="add-button" @click="showAddCategoryModal = true">
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M12 5V19M5 12H19" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
          </svg>
          添加分类
        </button>
      </div>
      </div>
      
      <div class="products-table-container">
        <table class="products-table">
          <thead>
            <tr>
              <th>ID</th>
              <th>产品名称</th>
              <th>图片</th>
              <th>分类</th>
              <th>价格</th>
              <th>库存</th>
              <th>状态</th>
              <th>电商链接</th>
              <th>视频</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="product in filteredProducts" :key="product.id">
              <td>{{ product.id }}</td>
              <td>{{ product.name }}</td>
              <td class="image-cell">
                <div v-if="product.images && product.images.length > 0" class="product-image-container">
                  <img :src="product.images[0]" alt="{{ product.name }}" class="product-thumbnail" @click="showImageGallery(product.images)">
                  <span v-if="product.images.length > 1" class="image-count">{{ product.images.length }}</span>
                </div>
                <span v-else class="no-image">无图片</span>
              </td>
              <td>{{ product.category }}</td>
              <td>¥{{ product.price }}</td>
              <td>{{ product.stock }}</td>
              <td>
                <span class="status-badge" :class="product.status">
                  {{ product.status === 'active' ? '上架' : '下架' }}
                </span>
              </td>
              <td class="links-cell">
                <div class="platform-links">
                  <a v-if="product.jdLink" :href="product.jdLink" target="_blank" class="platform-link jd">京东</a>
                  <a v-if="product.taobaoLink" :href="product.taobaoLink" target="_blank" class="platform-link taobao">淘宝</a>
                  <a v-if="product.douyinLink" :href="product.douyinLink" target="_blank" class="platform-link douyin">抖音</a>
                  <span v-else class="no-links">无</span>
                </div>
              </td>
              <td class="video-cell">
                <button v-if="product.videoUrl" class="video-button" @click="showVideo(product.videoUrl)">查看视频</button>
                <span v-else class="no-video">无</span>
              </td>
              <td>
                <div class="action-buttons">
                  <button class="edit-button" @click="editProduct(product)">
                    编辑
                  </button>
                  <button class="delete-button" @click="deleteProduct(product.id)">
                    删除
                  </button>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
        
        <div v-if="filteredProducts.length === 0" class="no-data">
          <p>暂无产品数据</p>
        </div>
      </div>
      
      <div class="pagination">
        <button class="pagination-button" :disabled="currentPage === 1" @click="currentPage--">
          上一页
        </button>
        <div class="page-numbers">
          <span v-for="page in totalPages" :key="page" 
                class="page-number" :class="{ active: page === currentPage }"
                @click="currentPage = page">
            {{ page }}
          </span>
        </div>
        <button class="pagination-button" :disabled="currentPage === totalPages" @click="currentPage++">
          下一页
        </button>
      </div>
      
      <!-- 添加/编辑产品弹窗 -->
      <div v-if="showAddProductModal || showEditProductModal" class="modal-overlay" @click="closeModal">
        <div class="modal-content add-product-modal" @click.stop>
          <div class="modal-header">
            <h3>{{ showEditProductModal ? '编辑产品' : '添加产品' }}</h3>
            <button class="close-button" @click="closeModal">×</button>
          </div>
          <form class="product-form" @submit.prevent="saveProduct">
            <div class="form-group info-row">
              <label class="info-label">产品名称</label>
              <input type="text" v-model="currentProduct.name" required class="edit-input"/>
            </div>
            <div class="form-group info-row">
              <label class="info-label">分类</label>
              <select v-model="currentProduct.category" required class="edit-select">
                <option v-for="category in categories" :key="category" :value="category">
                  {{ category }}
                </option>
              </select>
            </div>
            <div class="form-group info-row">
              <label class="info-label">价格</label>
              <input type="number" v-model="currentProduct.price" min="0" step="0.01" required class="edit-input"/>
            </div>
            <div class="form-group info-row">
              <label class="info-label">库存</label>
              <input type="number" v-model="currentProduct.stock" min="0" required class="edit-input"/>
            </div>
            <div class="form-group info-row">
              <label class="info-label">状态</label>
              <select v-model="currentProduct.status" required class="edit-select">
                <option value="active">上架</option>
                <option value="inactive">下架</option>
              </select>
            </div>
            <div class="form-group info-row">
              <label class="info-label">描述</label>
              <textarea v-model="currentProduct.description" rows="4" class="edit-textarea"></textarea>
            </div>
            <div class="form-group info-row">
              <label class="info-label">京东链接</label>
              <input type="url" v-model="currentProduct.jdLink" placeholder="https://item.jd.com/..." class="edit-input"/>
            </div>
            <div class="form-group info-row">
              <label class="info-label">淘宝链接</label>
              <input type="url" v-model="currentProduct.taobaoLink" placeholder="https://detail.tmall.com/..." class="edit-input"/>
            </div>
            <div class="form-group info-row">
              <label class="info-label">抖音链接</label>
              <input type="url" v-model="currentProduct.douyinLink" placeholder="https://v.douyin.com/..." class="edit-input"/>
            </div>
            <div class="form-group info-row">
              <label class="info-label">视频URL</label>
              <input type="url" v-model="currentProduct.videoUrl" placeholder="视频播放链接" class="edit-input"/>
            </div>
            <div class="form-group info-row">
              <label class="info-label">产品图片</label>
              <div class="image-upload-container">
                <div class="upload-button" @click="triggerFileInput">
                  <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M12 5V19M5 12H19" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                  </svg>
                  <span>上传图片</span>
                  <input type="file" ref="fileInput" accept="image/*" multiple style="display: none" @change="handleImageUpload">
                </div>
                <div v-if="currentProduct.images && currentProduct.images.length > 0" class="uploaded-images">
                  <div v-for="(image, index) in currentProduct.images" :key="index" class="image-preview">
                    <img :src="image" :alt="`产品图片 ${index + 1}`" class="preview-image">
                    <button class="remove-image" @click="removeImage(index)">×</button>
                  </div>
                </div>
                <div class="upload-tips">
                  支持JPG、PNG、GIF格式，可上传多张图片
                </div>
              </div>
            </div>
            <div class="form-actions">
              <button type="button" class="cancel-button" @click="closeModal">取消</button>
              <button type="submit" class="save-button">{{ showEditProductModal ? '保存' : '添加' }}</button>
            </div>
          </form>
        </div>
      </div>
      
      <!-- 图片画廊弹窗 -->
      <div v-if="showImageGallery" class="modal-overlay gallery-overlay" @click="closeImageGallery">
        <div class="gallery-modal" @click.stop>
          <div class="gallery-header">
            <span class="gallery-counter">{{ currentImageIndex + 1 }}/{{ currentImages.length }}</span>
            <button class="close-button" @click="closeImageGallery">×</button>
          </div>
          <div class="gallery-content">
            <button class="gallery-nav prev" @click="prevImage" v-if="currentImages.length > 1">
              <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M15 18L9 12L15 6" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
              </svg>
            </button>
            <img :src="currentImages[currentImageIndex]" :alt="`图片 ${currentImageIndex + 1}`" class="gallery-image">
            <button class="gallery-nav next" @click="nextImage" v-if="currentImages.length > 1">
              <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M9 18L15 12L9 6" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
              </svg>
            </button>
          </div>
        </div>
      </div>
      
      <!-- 添加分类弹窗 -->
      <div v-if="showAddCategoryModal" class="modal-overlay" @click="closeCategoryModal">
        <div class="modal-content" @click.stop>
          <div class="modal-header">
            <h3>添加分类</h3>
            <button class="close-button" @click="closeCategoryModal">×</button>
          </div>
          <div class="product-form">
            <div class="info-row">
              <label class="info-label">分类名称</label>
              <input 
                type="text" 
                class="edit-input" 
                v-model="newCategory" 
                placeholder="请输入分类名称"
              >
            </div>
          </div>
          <div class="form-actions">
            <button class="cancel-button" @click="closeCategoryModal">取消</button>
            <button class="save-button" @click="saveCategory">保存</button>
          </div>
        </div>
      </div>
    </div>
  </AdminLayout>
</template>

<script>
import AdminLayout from './AdminLayout.vue'
import ProductStore from '../../services/ProductStore.js'

export default {
  name: 'ProductsManagement',
  components: {
    AdminLayout
  },
  data() {
    return {
      products: [],
      categories: [],
      searchQuery: '',
      categoryFilter: 'all',
      currentPage: 1,
      itemsPerPage: 10,
      showAddProductModal: false,
      showEditProductModal: false,
      currentProduct: {
        id: '',
        name: '',
        category: '',
        price: '',
        stock: '',
        status: 'active',
        description: '',
        jdLink: '',
        taobaoLink: '',
        douyinLink: '',
        videoUrl: '',
        images: []
      },
      showAddCategoryModal: false,
      newCategory: '',
      showImageGallery: false,
      currentImages: [],
      currentImageIndex: 0
    }
  },
  created() {
    // 加载产品数据
    this.loadProducts();
    // 添加监听器以响应数据变化
    ProductStore.addListener(this.loadProducts);
  },
  beforeUnmount() {
    // 移除监听器
    ProductStore.removeListener(this.loadProducts);
  },
  computed: {
    filteredProducts() {
      let result = [...this.products];
      
      // 搜索过滤
      if (this.searchQuery) {
        const query = this.searchQuery.toLowerCase();
        result = result.filter(product => 
          product.name.toLowerCase().includes(query) ||
          product.description.toLowerCase().includes(query)
        );
      }
      
      // 分类过滤
      if (this.categoryFilter !== 'all') {
        result = result.filter(product => product.category === this.categoryFilter);
      }
      
      // 分页
      const startIndex = (this.currentPage - 1) * this.itemsPerPage;
      const endIndex = startIndex + this.itemsPerPage;
      return result.slice(startIndex, endIndex);
    },
    totalPages() {
      let result = [...this.products];
      
      // 搜索过滤
      if (this.searchQuery) {
        const query = this.searchQuery.toLowerCase();
        result = result.filter(product => 
          product.name.toLowerCase().includes(query) ||
          product.description.toLowerCase().includes(query)
        );
      }
      
      // 分类过滤
      if (this.categoryFilter !== 'all') {
        result = result.filter(product => product.category === this.categoryFilter);
      }
      
      return Math.ceil(result.length / this.itemsPerPage);
    }
  },
  methods: {
    // 加载产品数据
    async loadProducts() {
      if (!ProductStore.isLoading) {
        await ProductStore.loadProducts();
      }
      this.products = ProductStore.getAllProducts();
      this.categories = ProductStore.getCategories();
      // 如果没有选中分类，默认选择第一个分类
      if (!this.currentProduct.category && this.categories.length > 0) {
        this.currentProduct.category = this.categories[0];
      }
    },
    performSearch() {
      this.currentPage = 1;
    },
    
    resetFilters() {
      this.searchQuery = '';
      this.categoryFilter = 'all';
      this.currentPage = 1;
    },
    editProduct(product) {
      this.currentProduct = { ...product };
      this.showEditProductModal = true;
    },
    async deleteProduct(id) {
      if (confirm('确定要删除这个产品吗？')) {
        try {
          const success = await ProductStore.deleteProduct(id);
          if (success) {
            // 如果删除后当前页没有数据，返回上一页
            if (this.filteredProducts.length === 0 && this.currentPage > 1) {
              this.currentPage--;
            }
          }
        } catch (error) {
          console.error('删除产品失败:', error);
          alert('删除产品失败，请重试');
        }
      }
    },
    async saveProduct() {
      try {
        if (this.showEditProductModal) {
          // 编辑产品
          await ProductStore.updateProduct(this.currentProduct.id, this.currentProduct);
        } else {
          // 添加新产品
          await ProductStore.addProduct(this.currentProduct);
        }
        this.closeModal();
      } catch (error) {
        console.error('保存产品失败:', error);
        alert('保存产品失败，请重试');
      }
    },
    closeModal() {
      this.showAddProductModal = false;
      this.showEditProductModal = false;
      this.currentProduct = {
        id: '',
        name: '',
        category: '穿越机',
        price: '',
        stock: '',
        status: 'active',
        description: '',
        jdLink: '',
        taobaoLink: '',
        douyinLink: '',
        videoUrl: '',
        images: []
      };
    },
    showVideo(videoUrl) {
      // 简单实现：在新窗口中打开视频
      window.open(videoUrl, '_blank');
    },
    // 图片上传相关方法
    triggerFileInput() {
      this.$refs.fileInput.click();
    },
    async handleImageUpload(event) {
      const files = event.target.files;
      if (!files.length) return;
      
      if (!this.currentProduct.images) {
        this.currentProduct.images = [];
      }
      
      // 限制最多上传5张图片
      const maxImages = 5;
      const remainingSlots = maxImages - this.currentProduct.images.length;
      const filesToProcess = Math.min(files.length, remainingSlots);
      
      if (files.length > remainingSlots) {
        alert(`最多只能上传${maxImages}张图片，已添加${remainingSlots}张`);
      }
      
      // 显示加载状态
      const originalButtonText = this.$el.querySelector('.add-button')?.innerText;
      if (originalButtonText) {
        this.$el.querySelector('.add-button').innerText = '上传中...';
      }
      
      try {
        for (let i = 0; i < filesToProcess; i++) {
          const file = files[i];
          // 检查文件类型
          if (!file.type.match('image.*')) {
            alert('请上传图片文件');
            continue;
          }
          
          // 检查文件大小（限制5MB）
          if (file.size > 5 * 1024 * 1024) {
            alert('图片大小不能超过5MB');
            continue;
          }
          
          // 使用ProductStore上传图片
          const imageUrl = await ProductStore.uploadImage(file);
          this.currentProduct.images.push(imageUrl);
        }
      } catch (error) {
        console.error('上传图片失败:', error);
        alert('上传图片失败，请重试');
      } finally {
        // 恢复按钮文本
        if (originalButtonText) {
          this.$el.querySelector('.add-button').innerText = originalButtonText;
        }
        // 清空input，允许重复选择同一文件
        event.target.value = '';
      }
    },
    removeImage(index) {
      this.currentProduct.images.splice(index, 1);
    },
    showImageGallery(images) {
      this.currentImages = images;
      this.currentImageIndex = 0;
      this.showImageGallery = true;
    },
    closeImageGallery() {
      this.showImageGallery = false;
    },
    prevImage() {
      this.currentImageIndex = (this.currentImageIndex - 1 + this.currentImages.length) % this.currentImages.length;
    },
    nextImage() {
      this.currentImageIndex = (this.currentImageIndex + 1) % this.currentImages.length;
    },
    async saveCategory() {
      if (!this.newCategory.trim()) {
        alert('分类名称不能为空');
        return;
      }
      
      try {
        // 调用ProductStore添加分类
        const result = await ProductStore.addCategory(this.newCategory);
        
        if (result.success) {
          // 重新加载产品数据和分类列表
          this.loadProducts();
          alert('分类添加成功');
          this.closeCategoryModal();
        } else {
          alert(result.error || '添加分类失败');
        }
      } catch (error) {
        console.error('保存分类失败:', error);
        alert('添加分类失败，请重试');
      }
    },
    closeCategoryModal() {
      this.showAddCategoryModal = false;
      this.newCategory = '';
    }
  }
}
</script>

<style scoped>
.products-management {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  margin: 0;
}

.add-button {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: #4caf50;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.add-button:hover {
  background-color: #45a049;
}

.search-filter {
  display: flex;
  gap: 15px;
  margin-bottom: 20px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 280px;
  max-width: 500px;
}

.search-box svg {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 12px 15px 12px 45px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}

.filter-select {
  min-width: 150px;
}

.filter-select select {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  background-color: white;
  cursor: pointer;
}

.search-actions {
  display: flex;
  gap: 10px;
}

.search-button {
  padding: 12px 20px;
  background-color: #4caf50;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.search-button:hover {
  background-color: #45a049;
}

.reset-button {
  padding: 12px 20px;
  background-color: #f5f5f5;
  color: #666;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.reset-button:hover {
  background-color: #e0e0e0;
  border-color: #ccc;
}

.products-table-container {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  margin-bottom: 20px;
  max-height: 600px;
  overflow-y: auto;
  border: 1px solid #e8e8e8;
}

.products-table-container::-webkit-scrollbar {
  width: 8px;
}

.products-table-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.products-table-container::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.products-table-container::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.products-table {
  width: 100%;
  border-collapse: collapse;
}

.products-table th,
.products-table td {
  padding: 15px;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
}

.products-table th {
  background-color: #f5f5f5;
  font-weight: 600;
  color: #333;
  font-size: 14px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.products-table td {
  font-size: 14px;
  color: #666;
}

.status-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.status-badge.active {
  background-color: #e8f5e9;
  color: #4caf50;
}

.status-badge.inactive {
  background-color: #ffebee;
  color: #f44336;
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.edit-button {
  padding: 6px 12px;
  background-color: #2196f3;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.edit-button:hover {
  background-color: #1976d2;
}

.delete-button {
  padding: 6px 12px;
  background-color: #f44336;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.delete-button:hover {
  background-color: #d32f2f;
}

.no-data {
  padding: 60px 20px;
  text-align: center;
  color: #999;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  margin-left: 20px;
  padding: 10px 0;
}

.pagination-button {
  padding: 6px 12px;
  background-color: #fff;
  color: #333;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s;
  min-width: 60px;
  text-align: center;
}

.pagination-button:hover:not(:disabled) {
  color: #1890ff;
  border-color: #1890ff;
}

.pagination-button:disabled {
  color: #d9d9d9;
  cursor: not-allowed;
}

.page-numbers {
  display: flex;
  gap: 4px;
}

.page-number {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  color: #333;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s;
}

.page-number:hover {
  background-color: #f5f5f5;
  border-color: #ccc;
}

.page-number.active {
  background-color: #1890ff;
  color: white;
  border-color: #1890ff;
}

/* Modal styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  border-radius: 8px;
  padding: 30px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
  font-size: 20px;
  font-weight: bold;
  color: #333;
  margin: 0;
}

.close-button {
  background: none;
  border: none;
  font-size: 24px;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.close-button:hover {
  background-color: #f5f5f5;
  color: #333;
}

/* 产品表单样式 */
.add-product-modal {
  max-width: 700px;
}

.product-form {
  border: 2px solid #1890ff;
  border-radius: 8px;
  padding: 20px;
  margin: 20px 0;
  max-height: 60vh;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: #fafafa;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* 编辑模式输入框样式 */
.edit-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.3s;
}

.edit-input:focus {
  outline: none;
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

.edit-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 14px;
  resize: vertical;
  min-height: 60px;
}

.edit-textarea:focus {
  outline: none;
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

.edit-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 14px;
  background-color: white;
  cursor: pointer;
}

.edit-select:focus {
  outline: none;
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

/* 表单操作按钮样式 */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

.cancel-button {
  padding: 8px 20px;
  background-color: #f5f5f5;
  color: #666;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.cancel-button:hover {
  background-color: #e0e0e0;
  border-color: #ccc;
}

.save-button {
  padding: 8px 20px;
  background-color: #52c41a;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.save-button:hover {
  background-color: #73d13d;
}

/* 信息行样式 - 确保输入框和选择框竖向对齐 */
.product-form .info-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 15px;
}

.product-form .info-label {
  width: 120px;
  flex-shrink: 0;
  font-weight: 500;
  color: #333;
  padding-top: 8px;
}

.product-form .edit-input,
.product-form .edit-select,
.product-form .edit-textarea {
  flex: 1;
  align-self: flex-start;
}

/* 滚动条样式 */
.product-form::-webkit-scrollbar {
  width: 8px;
}

.product-form::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.product-form::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.product-form::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* 表单组样式 */
.form-group {
  margin-bottom: 0;
}

.save-button:hover {
  background-color: #45a049;
}

/* 电商链接样式 */
.platform-links {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.platform-link {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  text-decoration: none;
  transition: all 0.3s ease;
}

.platform-link.jd {
  background-color: #E1251B;
  color: white;
}

.platform-link.taobao {
  background-color: #FF4400;
  color: white;
}

.platform-link.douyin {
  background-color: #000000;
  color: white;
}

.platform-link:hover {
  opacity: 0.8;
}

/* 视频按钮样式 */
.video-button {
  padding: 4px 12px;
  background-color: #673AB7;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.video-button:hover {
  background-color: #5E35B1;
}

/* 图片上传样式 */
.image-upload-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.upload-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  border: 2px dashed #ddd;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  background-color: #fafafa;
  color: #666;
}

.upload-button:hover {
  border-color: #4caf50;
  background-color: #f0f9f0;
  color: #4caf50;
}

.uploaded-images {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.image-preview {
  position: relative;
  width: 100px;
  height: 100px;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-image {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  background-color: rgba(255, 0, 0, 0.8);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s ease;
}

.remove-image:hover {
  background-color: rgba(255, 0, 0, 1);
}

.upload-tips {
  font-size: 12px;
  color: #999;
}

/* 图片画廊样式 */
.gallery-overlay {
  background-color: rgba(0, 0, 0, 0.9);
  align-items: center;
  justify-content: center;
}

.gallery-modal {
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: transparent;
  color: white;
}

.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}

.gallery-counter {
  font-size: 14px;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 5px 10px;
  border-radius: 15px;
}

.gallery-content {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-image {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 4px;
}

.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  background-color: rgba(0, 0, 0, 0.5);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s ease;
}

.gallery-nav:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

.gallery-nav.prev {
  left: 10px;
}

.gallery-nav.next {
  right: 10px;
}

/* 表格特殊单元格样式 */
.image-cell {
  min-width: 80px;
  text-align: center;
}

.product-image-container {
  position: relative;
  display: inline-block;
}

.product-thumbnail {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.product-thumbnail:hover {
  transform: scale(1.1);
}

.image-count {
  position: absolute;
  bottom: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
}

.no-image {
  color: #999;
  font-size: 12px;
}

.links-cell,
.video-cell {
  min-width: 120px;
}

.no-links,
.no-video {
  color: #999;
  font-size: 12px;
}

/* Responsive design */
@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 15px;
  }
  
  .search-filter {
    flex-direction: column;
    align-items: stretch;
  }
  
  .products-table-container {
    overflow-x: auto;
  }
  
  .products-table {
    min-width: 800px;
  }
  
  .modal-content {
    margin: 20px;
    padding: 20px;
  }
}
</style>